package me.znext.learn.android;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.ArrayList;

public class NoteListAdapter extends ArrayAdapter<Note> {
  public NoteListAdapter(Context context, ArrayList<Note> notes) {
    super(context, 0, notes);
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    // Get the data item for this position
    Note note = getItem(position);
    // Check if an existing view is being reused, otherwise inflate the view
    if (convertView == null) {
      convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_note, parent, false);
    }
    // Lookup view for data population
    TextView time = (TextView) convertView.findViewById(R.id.time);
    TextView text = (TextView) convertView.findViewById(R.id.text);
    // Populate the data into the template view using the data object
    time.setText(note.time);
    text.setText(note.text);
    // Return the completed view to render on screen
    return convertView;
  }
}
